<?php
if(!defined('IN_KKFRAME')) exit();
if(!$_GET['skip']) include template('header');
?>

<div class="side">
<div class="side-box">
<?php
if(!$_K['uid']){
	include template('side_login');
}elseif(!$_GET['skip']){
	echo <<<EOF
<h2 id="reply_action">快速回帖</h2>
<form method="post" action="thread.php?id={$_K[tid]}">
<input type="hidden" id="replyto" name="replyto" value="" />
<p><textarea required name="contents" id="contents" placeHolder="在这里键入回复内容" onkeydown="if(event.ctrlKey && event.keyCode == 13) document.getElementById('submit').click();" style="width: 100% !important"></textarea></p>
<p class="text-right"><input type="submit" id="submit" class="g-button g-button-red" value="快速回帖" /></p>
</form>
EOF;
}
?>
</div>
</div>

<div class="page-info">
<?php
if($_K['member']['adminid']){
	echo <<<EOF
<div class="page-headers"><h3 class="head" onclick="show_mod_panel(this)">点击展开管理功能</h3></div>
<p id="mod_actions" style="display:none"><a href="modcp.php?action=delete_thread&tid={$tid}&hash={$_K[formhash]}" class="g-button g-button-submit" onclick="return confirm_action();">删除帖子</a> &nbsp; 帖子分类：
<select onchange="location.href='modcp.php?action=move_thread&tid={$tid}&hash={$_K[formhash]}&fid=' + this.value;">
EOF;
foreach($_K['config']['forums'] as $forumid=>$forumname){
	if($thread['fid'] == $forumid){
		echo "<option selected value=\"{$forumid}\">{$forumname}</option>";
	}else{
		echo "<option value=\"{$forumid}\">{$forumname}</option>";
	}
}
	echo <<<EOF
</select>
</p><br>
EOF;
	$_K['footer_js'] .= '<script type="text/javascript">function confirm_action(){ return confirm("您确定要进行本操作吗？\n选择继续可能将丢失数据！") ? true : false; }function show_mod_panel(obj){ document.getElementById("mod_actions").style.display=""; obj.innerHTML="管理功能"; }</script>';
}
?>
<div class="page-headers"><h1><?php echo $thread['subject'];?></h1></div>
<div class="postlist">
<?php
if($page > 1){
	echo '<a href="thread.php?id='.$_K['tid'].'&page='.($page - 1).'" id="prev_page_link" onclick="load_prev_page();return false;" class="page_loader">点击加载上一页</a>';
	echo '<div class="page_loader center" id="prev_page_waiter">加载中...</div><div id="prev_page_loader"></div>';
}
echo '<div id="posts">';
$i = 0;
foreach($postlist as $post){
	$i++;
	if($post['deleted']) continue;
	$position = ($page - 1)*10 + $i;
	$highlight = $post['pid']==$_GET['pid'] ? ' highlight' : '';
	if($_K['member']['adminid'] && $position > 1) $admin = "&nbsp;<a class=\"reply-post\" href=\"modcp.php?action=delete_post&pid={$post[pid]}&hash={$_K[formhash]}\" onclick=\"return confirm_action();\">删除</a>";
	echo '<div class="post '.($post['author'] == $_K['uid'] ? 'a' : 'na').$highlight.'">';
	$avatar = avatar($post['author']);
	echo "<img src=\"{$avatar}\" class=\"avatar\"><div class=\"contents clearfix\">";
	echo "<p class=\"info\">{$position} 楼 - {$post[author_name]} 发表于 ".dgmdate($post['time']).' <a href="javascript:;" class="reply-post" onclick="replyto('.$post['pid'].', \''.$position.'\')">回复本楼</a>'.$admin.'</p>';
	echo nl2br($post['content']);
	echo "</div></div>\r\n";
}
echo '</div>';
if($max_page > $page){
	echo '<div id="next_page_loader"></div><div class="page_loader center" id="next_page_waiter">加载中...</div>';
	echo '<a href="thread.php?id='.$_K['tid'].'&page='.($page + 1).'" id="next_page_link" class="page_loader text-right" onclick="load_next_page();return false;">点击加载下一页</a>';
}
?>
</div></div>

<?php
$_K['footer_js'] .= '<script type="text/javascript" src="system/javascript/replyto.js"></script><script type="text/javascript" src="system/javascript/kk_pager.js"></script><script type="text/javascript">var next_page = '.($page + 1).';var prev_page = '.($page - 1).';var max_page = '.$max_page.';var page_temp = "thread.php?id='.$tid.'"</script>';
if(!$_GET['skip']) include template('footer');